using UnityEngine;
using System.Collections;

public class MiniGun : Projectile 
{
	public float Damage{get {return _damage;}}
	public float FireRate{get {return _fireRate;}}
	public int Ammo{ get; private set;}
	//public WeaponSlot SlotNumber{get{return _slotNumber} set{}} 
	public GameObject Bullet;
	public bool WeaponActive;
	
	private float _damage;
	private float _fireRate;
	private bool gunIsReady;
	private float shieldDamage;

	public void Start()
	{
		Ammo = 100;
		_damage = 5;
		gunIsReady = true;
		_fireRate = 0.3f;
		shieldDamage = 3;
		WeaponActive = true;
	}
	
	public override void Fire ()
	{
		if(gunIsReady && WeaponActive && Ammo > 0)
		{	
			gunIsReady = false;
			for(int i = 0; i < 3; i++)
			{
				if(Ammo > 3)
					Ammo--;
				else
					Ammo = 0;
				GameObject tmp;
				tmp = Instantiate (Bullet, new Vector3(this.transform.position.x, this.transform.position.y+i-1, this.transform.position.z), transform.rotation) as GameObject;
				tmp.rigidbody.velocity = transform.TransformDirection(Vector3.right * 50);
			}
			StartCoroutine ("Cooldown",_fireRate);
			
		}
	}
	
	private IEnumerator Cooldown(float cd)
	{
		yield return new WaitForSeconds(cd);
		gunIsReady = true;
	}
	
	public override float  ShieldDamage()
	{
		return shieldDamage;
	}
	
	public override float HullDamage()
	{
		return _damage;
	}
}
